<?php

namespace App\Admin\Actions;

use Dcat\Admin\Actions\Action;
use Dcat\Admin\Actions\Response;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Traits\HasPermissions;
use Dcat\Admin\Widgets\Modal;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class SetUserArea extends RowAction
{
    /**
     * @return string
     */
	protected $title = '设置区域';

    /**
     * Handle the action request.
     *
     * @param Request $request
     *
     * @return Response
     */
    public function handle(Request $request)
    {
        // dump($this->getKey());

        return $this->response()->success('Processed successfully.')->redirect('/');
    }

    /**
     * @return string|array|void
     */
    public function confirm()
    {
        // return ['Confirm?', 'contents'];
    }

    /**
     * @param Model|Authenticatable|HasPermissions|null $user
     *
     * @return bool
     */
    protected function authorize($user): bool
    {
        return true;
    }

    public function render()
    {
        parent::render(); // TODO: Change the autogenerated stub

        return Modal::make()
            ->lg()
            ->title('设置区域')
            ->body(\App\Admin\Forms\SetUserArea::make()->payload(['id'=>$this->row->id,'identity_id'=>$this->row->identity_id]))
            ->button("设置区域"); // 这个button就是对应上面的按钮
    }

    /**
     * @return array
     */
    protected function parameters()
    {
        return [
            // 发送当前行 username 字段数据到接口
            'id' => $this->row->id,
        ];
    }
}
